package cn.itcast.nems.product.scheduler;

import cn.itcast.nems.product.dao.dataobject.ProductDO;
import cn.itcast.nems.product.dao.entity.ProductPriceRule;
import cn.itcast.nems.product.service.ProductPriceRuleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author liyong
 * create: 2023-09-04 13:45:02
 **/
public class ProductPriceRuleProcessor {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final List<ProductPriceRule> result;

    public ProductPriceRuleProcessor(ProductPriceRuleService productPriceRuleService,
                                     BaseDataProcessor baseDataProcessor,
                                     List<ProductDO> products,
                                     String operator) {
        ProductPriceRuleCal pprc = new ProductPriceRuleCal(products,
                baseDataProcessor.getTuitionFees(),
                baseDataProcessor.getPhases(),
                baseDataProcessor.getSchools(),
                operator);
        this.result = pprc.calculate();
        logger.info("需要更新的产品价格规则数 {} ", result.size());
        productPriceRuleService.updateProductPriceRule(result);
    }

    public List<ProductPriceRule> getResult() {
        return result;
    }

    public int getProcessCount() {
        return result != null ? result.size() : 0;
    }
}
